package com.web.sys.controller;

import java.util.List;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.web.sys.dto.UserQueryDTO;
import com.web.sys.model.SysUser;
import com.web.sys.sercice.ISysUserService;

@Controller
@RequestMapping("/user")
public class SysUserController {
	
	@Inject
	private ISysUserService sysUserService;

	private final Logger logger=LoggerFactory.getLogger(getClass());
	@RequestMapping(value="/querySysUserResource",method=RequestMethod.POST)
	public @ResponseBody List<SysUser> querySysUserResource(){
		List<SysUser> userList=sysUserService.queryAllSysUser();
		return userList;
	}
	@RequestMapping(value="/yh",method=RequestMethod.GET)
	public String toSysUserManagerPage(){
		return "/yh";
	}
	@RequestMapping(value="/queryUserform",method=RequestMethod.POST)
	public @ResponseBody List<SysUser> queryUserform(HttpServletRequest req,HttpSession session,UserQueryDTO dto){
		List<SysUser> userList=sysUserService.queryUserform(dto);
		return userList;
	}
	@RequestMapping(value="/saveUserform",method=RequestMethod.POST)
	public @ResponseBody String saveUserform(HttpServletRequest req,HttpSession session,UserQueryDTO dto){
		String err=sysUserService.saveUserform(dto);
		return err;
	}
	@RequestMapping(value="/create",method=RequestMethod.GET)
	public String toSysUserCreatePage(){
		return "user/create";
	}
	@RequestMapping(value="/compile",method=RequestMethod.GET)
	public String toSysUserCompilePage(String username,Model model){
		SysUser user=sysUserService.queryUserByName(username);
		model.addAttribute("user", user);
		return "user/compile";
	}
	@RequestMapping(value="/updateUserform",method=RequestMethod.POST)
	public @ResponseBody String updateUserform(HttpServletRequest req,HttpSession session,UserQueryDTO dto){
		String err=sysUserService.updateUserform(dto);
		return err;
	}
	@RequestMapping(value="/delete",method=RequestMethod.GET)
	public @ResponseBody String deleteSysUser(String username){
		String err=sysUserService.deleteUserByName(username);
		return err;
	}
}
